package com.example.zqh.controller;


import com.example.zqh.model.RespBean;
import com.example.zqh.pojo.params.OneStringOneNumber;
import com.example.zqh.service.DeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zqh
 * @since 2022-09-10
 */
@RestController
@RequestMapping("/dept")
@Api(tags = "部门表的增删改查")
public class DeptController {
    
    @Autowired
    DeptService deptService;
    
    /**
      * @Author: zqh
      * @Date: 
      * @Description: 添加一个部门，管理员接口
    */
    @ApiOperation(value = "部门添加接口（管理员接口）")
    @PostMapping("departmentAddInterface")
    @PreAuthorize("hasRole('ROLE_admin')")
    public RespBean departmentAddInterface(String name,String sc){
        return deptService.departmentAddInterface(name,sc);
    }
    
    /**
      * @Author: zqh
      * @Date: 
      * @Description: 删除部门
    */
    @ApiOperation(value = "部门删除接口（管理员接口）")
    @DeleteMapping("departmentDeleteInterface")
    @PreAuthorize("hasRole('ROLE_admin')")
    public RespBean departmentDeleteInterface(Integer id){
        return deptService.departmentDeleteInterface(id);
    }


    /**
      * @Author: zqh
      * @Date:
      * @Description: 修改部门的名字
    */
    @ApiOperation(value = "修改部门的名字（管理员接口）")
    @PreAuthorize("hasRole('ROLE_admin')")
    @PostMapping("changeTheNameOfTheDepartment")
    public RespBean changeTheNameOfTheDepartment(@RequestBody OneStringOneNumber oneStringOneNumber){
        return deptService.changeTheNameOfTheDepartment(oneStringOneNumber);
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 修改部门描述
    */
    @ApiOperation(value = "修改部门描述（管理员接口）")
    @PreAuthorize("hasRole('ROLE_admin')")
    @PostMapping("modifyDepartmentDescription")
    public RespBean modifyDepartmentDescription(@RequestBody OneStringOneNumber oneStringOneNumber){
        return deptService.modifyDepartmentDescription(oneStringOneNumber);
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 获取所有部门的数量
    */
    @GetMapping("getTheCountOfAllDepartments")
    @ApiOperation(value = "获取所有部门的数量（放行）")
    public RespBean getTheCountOfAllDepartments(){
        return deptService.getTheCountOfAllDepartments();
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 分页查询所有部门
    */
    @GetMapping("paginationToQueryAllDepartments")
    @ApiOperation(value = "分页查询所有部门（放行）")
    public RespBean paginationToQueryAllDepartments(Integer page,Integer size){
        return deptService.paginationToQueryAllDepartments(page,size);
    }



}

